package com.xuerhua.yxt.controller.sys.signup;

import com.xuerhua.yxt.controller.BaseController;
import com.xuerhua.yxt.model.Grid;
import com.xuerhua.yxt.page.Page;
import com.xuerhua.yxt.service.ITeacherSignUpService;
import com.xuerhua.yxt.utils.ExcelExportUtil;
import com.xuerhua.yxt.utils.ExportSetInfoUtil;
import com.xuerhua.yxt.vo.SignUpQueryVO;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@RequestMapping("sys/signUp/teacher")
@Controller
public class SysTeacherSignupController extends BaseController
{

  @Autowired
  private ITeacherSignUpService teacherSignUpService;

  @RequestMapping(value = {"", "/"})
  public String Index()
  {
    return "sys/signup/teacher";
  }
  @RequestMapping("pageQuery")
  @ResponseBody
  Object pageQuery(SignUpQueryVO vo) {
    try { Page page = new Page();
      page.setParams(vo);
      page.setPageNo(vo.getPage());
      page.setPageSize(vo.getRows());
      List list = this.teacherSignUpService.selectListByPage(page);

      Grid grid = new Grid();
      grid.setRows(list);
      grid.setTotal(page.getTotalRecord());
      return grid;
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }

  @RequestMapping("export")
  ModelAndView export(SignUpQueryVO vo) {
    ModelAndView modelAndView = new ModelAndView();
    try {
      Page page = new Page();
      page.setParams(vo);
      page.setPageSize(Integer.MAX_VALUE - 1);
      List list = this.teacherSignUpService.selectListByPage(page);

      LinkedHashMap map = new LinkedHashMap();
      String title = "应聘教师名单";
      map.put(title, list);

      List headNames = new ArrayList();
      headNames.add(new String[] { "姓名", "联系电话", "身份证号", "学历", "毕业学校", "毕业专业", "现工作单位", "应聘岗位", "教龄", "教师资格证", "职称", "获奖荣誉", "工作特长", "应聘时间" });
      List fieldNames = new ArrayList();
      fieldNames.add(new String[] { "name", "phone", "idNo", "education", "university", "major", "nowCompany", "position", "schoolAge", "teacherCertification", "titles", "prizes", "workFeatures", "signUpTime" });

      String[] titles = { title };

      ExportSetInfoUtil setInfo = new ExportSetInfoUtil(map, titles, headNames, fieldNames, null);
      this.request.setAttribute("exportDatas", setInfo);

      modelAndView = new ModelAndView(new ExcelExportUtil(title + ".xls", ""));
    } catch (Exception e) {
      e.printStackTrace();
    }
    return modelAndView;
  }
}